﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;


namespace DAL
{
    public class Student
    {
        public static string connectionString = ConfigurationManager.ConnectionStrings["projectbConnection"].ToString();
        public List<Model.Student> select(int courseId)
        {
            DataSet ds = new DataSet();
            List<Model.Student> student = new List<Model.Student>();
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                try
                {
                    conn.Open();
                    SqlCommand comm = new SqlCommand("select StudentName, StudentId from Student where StudentId not in (select StudentID from CourseDetails where CourseId="+courseId+")", conn);
                    SqlDataAdapter da = new SqlDataAdapter(comm);
                    da.Fill(ds,"Student");
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        Model.Student s = new Model.Student
                        {   
                            StudentName=row[0].ToString(),
                            StudentId=Convert.ToInt32(row[1])
                        };
                        student.Add(s);
                    }
                    
                    return student;
                }
                catch (SqlException e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
        public List<Model.Student> selected(int courseId)
            {
                DataSet ds = new DataSet();
                List<Model.Student> student = new List<Model.Student>();
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    try
                    {
                        conn.Open();
                        SqlCommand comm = new SqlCommand("select StudentName, StudentId from Student where StudentId in (select StudentID from CourseDetails where CourseId="+courseId+")" , conn);
                        SqlDataAdapter da = new SqlDataAdapter(comm);
                        da.Fill(ds);
                        foreach (DataRow row in ds.Tables[0].Rows)
                        {
                            Model.Student s = new Model.Student
                            {
                                StudentName = row[0].ToString(),
                                StudentId = Convert.ToInt32(row[1])
                            };
                            student.Add(s);
                        }
                        return student;
                    }
                    catch (SqlException e)
                    {
                        throw new Exception(e.Message);
                    }
                }
            }
        }
    }
       



    


